<?php

/**
 * @author: Tran Tuan
 * @email : trantuanckc@gmail.com
 * This is the model class for table "hoso".
 *
 * The followings are the available columns in table 'hoso':
 * @property integer $id
 * @property string $vitriungtuyen
 * @property integer $capbac_id
 * @property integer $kinhnghiem_id
 * @property integer $luong_id
 * @property integer $bangcap_id
 * @property string $muctieunghenghiep
 */
class Hoso extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Hoso the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'hoso';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('vitriungtuyen, capbac_id, kinhnghiem_id, luong_id, bangcap_id', 'required'),
			array('capbac_id, kinhnghiem_id, luong_id, bangcap_id', 'numerical', 'integerOnly'=>true),
			array('vitriungtuyen', 'length', 'max'=>150),
			array('muctieunghenghiep, thongtinbosung', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, vitriungtuyen, capbac_id, kinhnghiem_id, luong_id, bangcap_id, muctieunghenghiep', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                    'luong'         => array(self::BELONGS_TO, 'Luong', 'luong_id'),
                    'bangcap'       => array(self::BELONGS_TO, 'Bangcap', 'bangcap_id'),
                    'hs_loaihinh'      => array(self::HAS_MANY, 'HosoLoaihinh', 'hoso_id','with' => 'loaihinh','together' => false),
                    'hs_nganhnghe'     => array(self::HAS_MANY, 'HosoNganhnghe','hoso_id','with' => 'nganhnghe', 'together' => false),
                    'capbac'        => array(self::BELONGS_TO,' Capbac', 'capbac_id')   ,
                    'hs_thanhpho'      => array(self::HAS_MANY, 'HosoThanhpho', 'hoso_id','with' => 'thanhpho', 'together' => false),
                    'hs_quocgia'       => array(self::HAS_MANY, 'HosoQuocgia', 'hoso_id', 'with' => 'quocgia', 'together' => false),
                    'kinhnghiem'    => array(self::BELONGS_TO, 'Kinhnghiem', 'kinhnghiem_id')
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'vitriungtuyen' => 'Vị trí ứng tuyển',
			'capbac_id' => 'Cấp bậc',
			'kinhnghiem_id' => 'Kinh nghiệm',
			'luong_id' => 'Lương',
			'bangcap_id' => 'Bằng cấp',
			'muctieunghenghiep' => 'Mục tiêu nghề nghiệp',
                        'thongtinbosung'    => 'Thông tin bổ sung'
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('vitriungtuyen',$this->vitriungtuyen,true);
		$criteria->compare('capbac_id',$this->capbac_id);
		$criteria->compare('kinhnghiem_id',$this->kinhnghiem_id);
		$criteria->compare('luong_id',$this->luong_id);
		$criteria->compare('bangcap_id',$this->bangcap_id);
		$criteria->compare('muctieunghenghiep',$this->muctieunghenghiep,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}